// Loesung_von_Aufgabe_4.7_1_Parallelschaltung

float U; // Spannung in Volt
float R; // Gesamtwiderstand in Ohm
float R1 = 20; // Widerstand in Ohm
float R2 = 5; // Widerstand in Ohm
float I; // Strom in Ampere
float I1; // Teilstrom in Ampere
float I2; // Teilstrom in Ampere

void setup()
{
  size(800, 600);
}

void draw()
{
  background(255);

  // Die Leitungen des Stromkreises werden gezeichnet
  stroke(0);
  strokeWeight(3);
  fill(255);
  beginShape();
  vertex(360, 440);
  vertex(180, 440);
  vertex(180, 100);
  vertex(620, 100);
  vertex(620, 440);
  vertex(440, 440);
  endShape();

  line(180, 290, 620, 290);

  // Kontakte
  ellipse(360, 440, 10, 10);
  ellipse(440, 440, 10, 10);
  ellipse(180, 290, 10, 10);
  ellipse(620, 290, 10, 10);

  // Strommessgeräte
  ellipse(180, 375, 80, 80);
  ellipse(300, 289, 80, 80);
  ellipse(300, 99, 80, 80);

  // Widerstand R1
  stroke(0);
  strokeWeight(3);
  fill(255);
  rect(440, 264, 106, 48);

  // Widerstand R2
  stroke(0);
  strokeWeight(3);
  fill(255);
  rect(440, 77, 106, 48);

  // Konstruktion des Schiebereglers
  stroke(0, 0, 255);
  strokeWeight(2);
  fill(200);
  rect(200, 500, 400, 20);

  if (mouseX > 200 && mouseX <= 600 && mouseY > 500 && mouseY < 520)
  {
    U = ((mouseX)-195)/10;

    stroke(255, 0, 0);
    strokeWeight(30);
    point(mouseX, 510);
  } else
  {
    U = 0;
    stroke(255, 0, 0);
    strokeWeight(30);
    point(205, 510);
  }

  // Berechnung von R
  R = 1/((1/R1)+(1/R2));

  // Berechnung von I und der Teilströme I1 und I2
  I = U/R;
  I1 = U/R1;
  I2 = U/R2;

  // Beschriftung
  fill(0);
  textSize(24);
  text("U in V = " +U, 326, 413);
  text("I1 in A", 260, 237);
  text("   " +(float)round(10*I1)/10, 260, 300);
  text("I2 in A", 260, 46);
  text("   " +(float)round(10*I2)/10, 260, 106);
  text("R1 in \u03A9 = " +R1, 415, 237);
  text("R2 in \u03A9 = " +R2, 415, 46);
  text("I in A     " +(float)round(10*I)/10, 80, 385);
}